package com.app.bussinesslocator.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.app.bussinesslocator.R;
import com.app.bussinesslocator.Utils.IOUtils;
import com.app.bussinesslocator.bean.ObjOpenHours;

public class OpenHourAdapter extends PagerAdapter{
	
	Context context;
	ArrayList<ObjOpenHours> objOpenHours;
	LayoutInflater inflater;

	public OpenHourAdapter(Context context, ArrayList<ObjOpenHours> objOpenHours) {  
		this.context = context;
		this.objOpenHours = objOpenHours;
	}



	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		((ViewPager) container).removeView((RelativeLayout) object);
	}

	@Override
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
			return objOpenHours.size();
	}


	@Override
	public int getItemPosition(Object object) {
		return POSITION_NONE;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == ((RelativeLayout)object);
	}



	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		TextView txtThoigian;
		TextView txtThuNgay;
		
		
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(R.layout.open_hours_item, container, false);
		
		txtThuNgay = (TextView) v.findViewById(R.id.txt_thungay);
//		txtThoigian = (TextView) v.findViewById(R.id.txt_thoigian);
		
		txtThuNgay.setText(IOUtils.toOnlyFirstUpcase(objOpenHours.get(position).getThuNgay())+"      "+objOpenHours.get(position).getThoigianMocua().toUpperCase());
//		txtThoigian.setText(objOpenHours.get(position).getThoigianMocua());
		
		// add viewpager item to viewpager
		((ViewPager) container).addView(v);
		
		return v;
	}
	
	
	
	

}
